import { createSlice } from '@reduxjs/toolkit';
import { UserState } from '@/domain/user';

const initialState: UserState = { userInfo: { name: '张三', age: 30 }, token: 'i am token' };

const userSlice = createSlice({
    name: 'user',
    initialState,
    reducers: {
        setUserInfo: (state, actions) => {
            state.userInfo = actions.payload || {};
        },
        setToken: (state, actions) => {
            state.token = actions.payload || '';
        }
    },
});

export const { setUserInfo, setToken } = userSlice.actions;

export default userSlice.reducer;

export type UserRootState = { user: UserState };